package binaryTree.LayerOrderTraversal;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
//多叉树层序遍历
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
}
public class Basic429 {
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> list = new ArrayList<List<Integer>>();
        Deque<Node> que = new LinkedList<>();
        if (root == null) {
            return list;
        }
        que.offerLast(root);
        while (!que.isEmpty()) {
            int size = que.size();
            List temp = new ArrayList<Integer>();
            while (size > 0) {
                Node pop = que.pollFirst();
                temp.add(pop.val);
                if (pop.children != null) {
                    for (Node a : pop.children
                    ) {
                        que.offerLast(a);
                    }
                }
                size--;

            }
            list.add(temp);
        }
        return  list;

    }

    public static void main(String[] args) {

//        Basic429 basic429 = new Basic429();
//        basic429.levelOrder()
    }
}